<template>
  <div class="myModal">
      <div class="modal-box">
        <div class="modal-title">
          {{title}}
        </div>
        <div :class="{'modal-content': true}" >
          <!-- <slot :todo="todo"></slot> -->
          <slot ></slot>
        </div>
        <div class="modal-btn" v-if="useBtn">
          <div
            class="cancel"
            :style="{color: btnLeft.fontColor, backgroundColor: btnLeft.bgColor}"
            @click="cancelFn"
          >
            {{btnLeft.text}}
          </div>
          <div
           class="sure"
            :style="{color: btnRight.fontColor, backgroundColor: btnRight.bgColor}"
            @click='sureFn'
          >
            {{btnRight.text}}
          </div>
        </div>
      </div>
  </div>
</template>

<script>
export default {
  data() {
    return {

    }
  },
  props: {
    title: {
      default: '这里是标题',
      type: String
    },
    content: {
      default: '',
      type: String
    },
    btnLeft: {
      default: () => {
        return {
          text: '取消',
          fontColor: '#666',
          bgColor: '#fff'
        }
      },
      type: Object
    },
    btnRight: {
      default: () => {
        return {
          text: '确定',
          fontColor: '#000',
          bgColor: '#fff'
        }
      },
      type: Object
    },
    useBtn: {
      default: false,
      type: Boolean
    },
    todo: {
      type: Array
    }
  },
  methods: {
    // 向父组件发送btnLeftFn事件，父组件监听@cancelFn事件
    cancelFn() {
      this.$emit('cancelFn')
    },
    sureFn() {
      this.$emit('sureFn')
    }
  }
}
</script>

<style lang="scss" scoped>
.myModal{
  overflow: hidden;
  width: 100%;
  // height: 100vh;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0,0,0,.5);
  z-index: 9999;
  .modal-box{
    overflow: hidden;
    // padding: 0 10px;
    box-sizing: border-box;
    width: 80%;
    background-color: #fff;
    border-radius: 10px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);
    .modal-title{
      margin: 0 10px;
      height: 40px;
      line-height: 40px;
      text-align: center;
      border-bottom: 1px solid #ccc;
    }
    .modal-content{
      margin: 0 10px;
      min-height: 50px;
    }
    .lh {
      line-height: 50px;
    }
    .modal-btn{
      width: 100%;
      .cancel,
      .sure{
        display: inline-block;
        width: 50%;
        height: 40px;
        line-height: 40px;
        text-align: center;
      }
    }
  }
}
</style>
